//
//  BJMineViewController.m
//  DangXiao
//
//  Created by APPLE on 16/12/5.
//  Copyright © 2016年 APPLE. All rights reserved.
//

#import "BJMineViewController.h"
#import "BJButton.h"
#import "BJSettingsTableViewCell.h"
#import "BJYouXiuDangYuanViewController.h"
#import "BJLoginViewController.h"

@interface BJMineViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *myTableView;

@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) NSMutableArray *titleArray;
@property (nonatomic, strong) NSMutableArray *titleImageArray;
@end

@implementation BJMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的";
    _titleArray = [[NSMutableArray alloc]initWithObjects:@"我的足迹",@"我的收藏",@"我的评论",@"我的作业",@"我的考试",@"我的下载",@"我的红花", nil];
    _titleImageArray = [[NSMutableArray alloc]initWithObjects:@"zu",@"shou_w",@"ping",@"zuoy",@"kaos",@"xiaz",@"hua", nil];
}

- (void)initHeaderViewUI{
    
    _headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, BILIHEIGHT(135))];
    _headerView.backgroundColor = BaseColor;
    
    BJButton *loginBtn = [BJButton buttonWithType:(UIButtonTypeCustom)];
    loginBtn.titleLablees.text = @"登录";
    loginBtn.titleLablees.textColor = [UIColor whiteColor];
    loginBtn.titleLablees.font = FontVlaue(12);
    [loginBtn addTarget:self action:@selector(didClickLoginBtn:) forControlEvents:(UIControlEventTouchUpInside)];
//    loginBtn.imageViews.image = [UIImage imageNamed:@"wei"];
    [_headerView addSubview:loginBtn];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_headerView.mas_centerX);
        make.top.mas_equalTo(BILIHEIGHT(25));
        make.size.mas_equalTo(CGSizeMake(BILIWIDTH(80), BILIWIDTH(80)));
    }];
}

#pragma mark ---- 点击“登录”按钮
- (void)didClickLoginBtn:(UIButton *)btn{
    BJLoginViewController *VC = [[BJLoginViewController alloc]init];
//    BJYouXiuDangYuanViewController *VC = [[BJYouXiuDangYuanViewController alloc]init];
    VC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:VC  animated:YES];
}

#pragma mark ---- 设置TbaleView
- (void)initUI{

    [self initHeaderViewUI];
    _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - TabBar_HEIGHT) style:(UITableViewStylePlain)];
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    _myTableView.backgroundColor = GrayLabel;
    _myTableView.tableHeaderView = _headerView;
    //    注册cell
    [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [_myTableView registerClass:[BJSettingsTableViewCell class] forCellReuseIdentifier:@"BJSettingsTableViewCell"];
    [self.view addSubview:_myTableView];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else{
        return _titleArray.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        BJSettingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BJSettingsTableViewCell" forIndexPath:indexPath];
        return cell;
    }else{
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"cell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = _titleArray[indexPath.row];
        cell.textLabel.font = FontVlaue(15);
        cell.imageView.image = [UIImage imageNamed:_titleImageArray[indexPath.row]];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return BILIHEIGHT(95);
    }else{
        return BILIHEIGHT(43);
    }
}

//static BJTipHeaderTableViewCell *cellView;
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//    
//    
//    cellView  = [[BJTipHeaderTableViewCell alloc]init];
//    cellView.backgroundColor = GrayLabel;
//    cellView.nameLabel.text = @"焦点新闻";
//    //        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapView:section:)];
//    //        [cellView addGestureRecognizer:tap];
//    return cellView;
//    
//}
//
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return BILIHEIGHT(10);
    }else{
    return 0.001;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //    BJJingPinClassDetailViewController *VC = [[BJJingPinClassDetailViewController alloc]init];
    //    [self.navigationController pushViewController:VC animated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
